import { View } from "../../../mvc/core/View";
import { LayerManager } from "../../manager/LayerManager";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { Language } from "../../../../extend/language/Language";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { SecTimer } from "../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../com/gengine/core/frame/TimerType";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class EatParadePanel
    
    export  class EatParadePanel extends View
    {
        constructor()
        {
            super();
            this.layer = LayerManager.uiLayer;
            this.show();
            this.initUI();
            return;
        }

        /* internal  */initUI(): void
        {
            LoaderHelp.addResCallBack(ResFileConst.eatParade, this.onLoadedHandler);
            ObjCreate.createBg(0, 0, 650, 35, this, ImagesConst.SelectedBg);
            this._readyBit = new Object /* flash.display.Bitmap */();
            this._readyBit.x = 30;
            this._readyBit.y = 8;
            addChild(this._readyBit);
            this._startBit = new Object /* flash.display.Bitmap */();
            this._startBit.x = 30;
            this._startBit.y = 8;
            addChild(this._startBit);
            var loc1;
            this._startBit.visible = loc1 = false;
            this._readyBit.visible = loc1;
            this._decTxt = ObjCreate.createTextField("", 475, 7, 80, 25, this);
            this._breakBtn = ObjCreate.createGButton(Language.getString(200106), 625, 5, 50, 25, this);
            this._breakBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onClickHandler);
            return;
        }

        /* internal  */onLoadedHandler(): void
        {
            this._readyBit.bitmapData = GlobalClass.getBitmapData(ImagesConst.eatParadeReady);
            this._startBit.bitmapData = GlobalClass.getBitmapData(ImagesConst.eatParadeStart);
            return;
        }

        protected onClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.BreakEatParade));
            return;
        }

        public setTime(arg1: int, arg2: Boolean): void
        {
            this._isStart = arg2;
            this._time = arg1;
            this.startCountDown();
            return;
        }

        /* internal  */startCountDown(): void
        {
            if (!this._timer) 
            {
                this._timer = new SecTimer();
                this._timer.addListener(TimerType.ENTERFRAME, this.onTimerHandler);
                this._timer.start();
            }
            return;
        }

        /* internal  */onTimerHandler(arg1: SecTimer): void
        {
            --this._time;
            this.setProcessBitmap(this._isStart);
            if (this._time < 0) 
            {
                this.clear();
            }
            return;
        }

        public setProcessBitmap(arg1: Boolean): void
        {
            if (arg1) 
            {
                this._dec = "";
                this._startBit.visible = arg1;
                this._readyBit.visible = !arg1;
            }
            else 
            {
                this._dec = String(this._time);
                this._startBit.visible = arg1;
                this._readyBit.visible = !arg1;
            }
            this._decTxt.htmlText = "<font color=\'#ffffff\'><b>" + this._dec + "</b></font>";
            return;
        }

        public clear(): void
        {
            if (this._timer) 
            {
                this._timer.stop();
                this._timer.dispose();
                this._timer = null;
            }
            this._decTxt.htmlText = "";
            return;
        }

        /* internal */ /* var */_decTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_breakBtn: GButton;

        /* internal */ /* var */_readyBit: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_startBit: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_time: int;

        /* internal */ /* var */_timer: SecTimer;

        /* internal */ /* var */_isStart: Boolean;

        /* internal */ /* var */_dec: string;
    }
